import { escape2Html, html2Escape } from '@/libs/utils'

const commons = {
  methods: {
    //特殊字符处理
    html2Escape(str) {
      return html2Escape(str)
    },
    escape2Html(str) {
      return escape2Html(str)
    },
    //获取数组对象中匹配属性所在的index
    getIndex(originArr, props, val) {
      let arrIndex = 0;
      originArr.forEach((item, index) => {
        if (item[props] === val) {
          arrIndex = index
        }
      })
      return arrIndex;
    },
    //前端分页函数
    fontPaging(originArr, pageParams) {
      let arr = [...originArr];
      let { pageIndex, pageSize } = pageParams;
      return arr.slice((pageIndex - 1) * pageSize, pageIndex * pageSize)
    },
    //过滤对象中的空值
    filterObjEmpty(obj) {
      let newObj = {}
      for (let key in obj) {
        if (obj[key]) {
          newObj[key] = obj[key]
        }
      }
      return newObj
    },
  }
}
export default commons
